from flask import jsonify


def is_valid_url(url):
    if not url:
        return jsonify({'error': 'url不能为空'}), 400
    elif "blog.csdn.net" not in url:
        return jsonify({'error': 'url非csdn博客链接'}), 400
    else:
        return url


def be_html(new_title, author_url, content):
    html_str = f'''
                    <!DOCTYPE html>
                    <html lang="en">
                    <head>
                        <meta charset="UTF-8">
                        <title>{new_title}</title>
    <style>
    /* 基本重置 */
    body,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p,
    ul,
    ol,
    li,
    figure,
    figcaption,
    blockquote,
    dl,
    dd {{
      margin: 0;
      padding: 0;
    }}

    /* 标题样式 */
    h1 {{
      font-size: 2em;
      color: #00050a;
      margin-bottom: 0.5em;
      border-bottom: 2px solid #0056b3;
      padding-bottom: 0.5em;
    }}

    h2 {{
      font-size: 1.5em;
      color: #01163b;
      margin-top: 1em;
      margin-bottom: 0.5em;
    }}

    h3 {{
      font-size: 1.2em;
      color: #003f86;
      margin-top: 0.8em;
      margin-bottom: 0.5em;
    }}

    /* 段落和链接样式 */
    p {{
      margin-bottom: 1em;
    }}

    a {{
      color: #f90a0a;
      text-decoration: none;
    }}

    a:hover {{
      text-decoration: underline;
    }}

    /* 代码块样式 */
    pre,
    code {{
      background-color: #545151;
      font-family: 'Courier New', monospace;
      color: #ffffff;
    }}

    code {{
      padding: 2px 4px;
      border-radius: 3px;
    }}

    pre {{
      padding: 10px;
      border: 1px solid #ddd;
      # overflow-x: auto;
      white-space: pre-wrap;
    }}

    /* 引用样式 */
    blockquote {{
      background-color: #eaeaea;
      border-left: 4px solid #ddd;
      padding: 10px 20px;
      margin-bottom: 1em;
    }}

    /* SVG 图标样式 */
    svg {{
      display: none;
    }}
  </style>
                    </head>
                    <body>
                        <a href="{author_url}">原作者博客</a>
                        {content}
                    </body>
                    </html>
                '''
    return html_str
